package com.mybatispluslambda.lambda;

import com.baomidou.mybatisplus.core.toolkit.support.BiIntFunction;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.util.HashMap;

class Foo {
    Foo() throws Exception {
    }

    private static void bar(Object o) {
        new Exception().printStackTrace();
    }

    public static void main(String[] args) throws Throwable {
//        new Foo().mh0.invokeExact("你好.0");
//        new Foo().mh1.invoke("你好.1");
//        MethodHandle mh0 = new Foo().mh0;
//        MethodHandles.dropArguments(mh0, 0, int.class);
        MethodHandles.Lookup l = MethodHandles.lookup();
        MethodType t = MethodType.methodType(void.class, Object.class);
        MethodHandle mh = l.findStatic(Foo.class, "bar", t);
        mh.invokeExact(new Object());
    }



    public static MethodHandles.Lookup lookup() {
        return MethodHandles.lookup();
    }

    // 获取方法句柄的不同方式
    MethodHandles.Lookup l = Foo.lookup(); // 具备 Foo 类的访问权限
    Method m = Foo.class.getDeclaredMethod("bar", Object.class);
    MethodHandle mh0 = l.unreflect(m);

    MethodType t = MethodType.methodType(void.class, Object.class);
    MethodHandle mh1 = l.findStatic(Foo.class, "bar", t);
}

